<?php

if (PHP_SAPI == 'cli')

    die('This example should only be run from a Web Browser');

global $_GPC,$_W;

$rid= intval($_GPC['rid']);

if(empty($rid)){

    message('抱歉，传递的参数错误！','', 'error');              

}

//$list = pdo_fetchall("SELECT a.*,b.* FROM ".tablename('laoyou_csyx_winning')." as a  left join ".tablename('laoyou_csyx_fans')." as b on a.rid=b.rid and  a.from_user=b.openid  WHERE a.rid = :rid and a.weid=:weid   ORDER BY a.id DESC " , array(':rid' => $rid,':weid'=>$_W['weid']));
$list = pdo_fetchall("SELECT * FROM " . tablename('laoyou_csyx_winning') ." WHERE rid = ".$rid." AND weid = ".$_W['uniacid']." ORDER BY id DESC");


foreach ($list as &$row) {

	if($row['status'] == 1){

		$row['status']='未兑换';

	}else if($row['status'] == 2){

		$row['status']='已兑换';

	}

}

$tableheader = array('ID', 'sn码', '奖项', '奖品名称', '状态' ,'领取者微信号', '姓名', '电话', '收货地址', '中奖时间', '使用时间');

$html = "\xEF\xBB\xBF";

foreach ($tableheader as $value) {

	$html .= $value . "\t ,";

}

$html .= "\n";

foreach ($list as $value) {

	$html .= $value['id'] . "\t ,";

	$html .= $value['award_sn'] . "\t ,";	

	$html .= $value['name'] . "\t ,";	

	$html .= $value['description'] . "\t ,";	

	$html .= $value['status'] . "\t ,";	

	$html .= $value['from_user'] . "\t ,";	
	
	$html .= $value['username'] . "\t ,";	
	
	$html .= $value['tel'] . "\t ,";	
	
	$html .= $value['address'] . "\t ,";	

	$html .= date('Y-m-d H:i:s', $value['createtime']) . "\t ,";	

	$html .= ($value['consumetime'] == 0 ? '未使用' : date('Y-m-d H:i',$value['consumetime'])) . "\n";		

}





header("Content-type:text/csv");

header("Content-Disposition:attachment; filename=全部数据.csv");



echo $html;

exit();

